﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class BufferedConsole : IDisposable
{
    private StringBuilder buffy;
    private const int maxSize = 25;

    public BufferedConsole()
    {
        this.buffy = new StringBuilder(maxSize);
    }

    public void Write(string str)
    {
        if (str != null)
        {
            for (int i = 0; i < str.Length; i++)
            {
                if (this.buffy.Length == maxSize)
                {
                    Console.Write(this.buffy.ToString());
                    this.buffy.Clear();
                }
                else
                {
                    this.buffy.Append(str[i]);
                }
            }
        }
    }

    ~BufferedConsole()
    {
        this.Dispose(false);
    }

    public void Dispose()
    {
        this.Dispose(true);
        GC.SuppressFinalize(this);
    }

    private void Dispose(bool disposing)
    {
        if (disposing)
        {
            
        } 
        Console.Write(this.buffy.ToString());
        this.buffy.Clear();
        Console.WriteLine("buffer cleared");
    }

}
